import '../helper/dioHelper.dart';

class XHNL {
  double H;
  double XHDKD;
  double CSDKD;
  double JZKD;
  double XHD;
  double CSD;
  double JZ;

  XHNL(this.H, this.XHDKD, this.CSDKD, this.JZKD, this.XHD, this.CSD, this.JZ);
  XHNL.fromJson(Map<String, dynamic> json)
      : H = json["H"],
        XHDKD = json["XHDKD"] * 1.0,
        CSDKD = json["CSDKD"] * 1.0,
        JZKD = json["JZKD"] * 1.0,
        XHD = json["XHD"] * 1.0,
        CSD = json["CSD"] * 1.0,
        JZ = json["JZ"] * 1.0;
  Map<String, dynamic> toJson() => {
        'H': H,
        'XHDKD': XHDKD,
        'CSDKD': CSDKD,
        'JZKD': JZKD,
        'XHD': XHD,
        'CSD': CSD,
        'JZ': JZ,
      };
  static Future<bool> Add(XHNL x1) async {
    var response = await DioHelper.Post("/XHNL/Add", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<bool> Update(XHNL x1) async {
    var response = await DioHelper.Post("/XHNL/Update", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<bool> Delete(XHNL x1) async {
    var st = x1.toJson();
    var response = await DioHelper.Post("/XHNL/Delete", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<XHNL?> Get(String h0, x, c, p) async {
    print(x);
    var response =
        await DioHelper.Get("/DayData/GetXHNL?h0=$h0&x=$x&c=$c&p=$p&", {});
    print(response.data);
    if (response.statusCode == 200) return new XHNL.fromJson(response.data);
    return null;
  }

  static Future<List<XHNL>> GetList(
      String where, dynamic data, int pageIndex, int pageSize) async {
    var response = await DioHelper.Post("/XHNL/GetListByWhere", {
      "Where": where,
      "obj": data,
      "PageIndex": pageIndex,
      "PageSize": pageSize,
    });
    var list1 = <XHNL>[];
    if (response.statusCode == 200) {
      for (var x in response.data) {
        list1.add(new XHNL.fromJson(x));
      }
    }
    return list1;
  }

  static Future<List<XHNL>> GetAllList() async {
    var response = await DioHelper.Get("/XHNL/GetAllList", {});
    var list1 = <XHNL>[];
    if (response.statusCode == 200) {
      for (var x in response.data) {
        list1.add(new XHNL.fromJson(x));
      }
    }
    return list1;
  }
}
